<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //完美数
        var start = +prompt('寻找范围内的完美数,输入起点:');
        var end = +prompt("输入终点:");
        function findPerfect(start, end) {
            var result = '';
            for (var i = start; i <= end; i++) {
                var sum = 0;
                var all = [];
                for (var j = 1; j < i; j++) {
                    if (i % j == 0) sum += j;
                }
                if (sum === i) result += i + ' ';
            }
            return result;
        }
        console.log(start + "到" + end + "的完美数有: " + findPerfect(start, end));

        //冒泡排序
        var how = true;//false为降序,true为降序
        var num = [45, 19, 8, 65, 56, 9, 14, 67];
        function callSort(num, how) {
            var max = 0;
            while (max++ < num.length) {
                for (var i = 1; i < num.length-max; i++) {
                    if (how ? num[i - 1] > num[i] : num[i - 1] < num[i]) {
                        var temp = num[i];
                        num[i] = num[i - 1];
                        num[i - 1] = temp;
                    }
                }
            }
            return num;
        }
        console.log("当前为升序排序");
        console.log(callSort(num, how));
    </script>
</body>

</html>